﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace hcrainMvc.DAL
{
	/// <summary>
	/// 数据访问类:herp_inoutorder
	/// </summary>
	public partial class herp_inoutorder
	{
		public herp_inoutorder()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(long id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from herp_inoutorder");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int64)
			};
			parameters[0].Value = id;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(hcrainMvc.Model.herp_inoutorder model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into herp_inoutorder(");
			strSql.Append("gid,type,sontype,sontypeid,sontypeinfo,orderNo,storeid,state,endtime,addtime,adduserid,addusername,allprice,inoutusertype,inoutuserid,inoutusername,inoutuseraddress,inoutusertel,inoutuserteluser,dataadduserid,datadepid,databranchid,datadepname,databranchname,dataaddusername,dataaddtime)");
			strSql.Append(" values (");
			strSql.Append("@gid,@type,@sontype,@sontypeid,@sontypeinfo,@orderNo,@storeid,@state,@endtime,@addtime,@adduserid,@addusername,@allprice,@inoutusertype,@inoutuserid,@inoutusername,@inoutuseraddress,@inoutusertel,@inoutuserteluser,@dataadduserid,@datadepid,@databranchid,@datadepname,@databranchname,@dataaddusername,@dataaddtime)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@gid", MySqlDbType.VarChar,36),
					new MySqlParameter("@type", MySqlDbType.VarChar,50),
					new MySqlParameter("@sontype", MySqlDbType.VarChar,50),
					new MySqlParameter("@sontypeid", MySqlDbType.Int64,20),
					new MySqlParameter("@sontypeinfo", MySqlDbType.VarChar,200),
					new MySqlParameter("@orderNo", MySqlDbType.VarChar,100),
					new MySqlParameter("@storeid", MySqlDbType.Int64,20),
					new MySqlParameter("@state", MySqlDbType.VarChar,100),
					new MySqlParameter("@endtime", MySqlDbType.DateTime),
					new MySqlParameter("@addtime", MySqlDbType.DateTime),
					new MySqlParameter("@adduserid", MySqlDbType.Int64,20),
					new MySqlParameter("@addusername", MySqlDbType.VarChar,100),
					new MySqlParameter("@allprice", MySqlDbType.Decimal,10),
					new MySqlParameter("@inoutusertype", MySqlDbType.VarChar,10),
					new MySqlParameter("@inoutuserid", MySqlDbType.Int64,20),
					new MySqlParameter("@inoutusername", MySqlDbType.VarChar,100),
					new MySqlParameter("@inoutuseraddress", MySqlDbType.VarChar,200),
					new MySqlParameter("@inoutusertel", MySqlDbType.VarChar,100),
					new MySqlParameter("@inoutuserteluser", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataadduserid", MySqlDbType.Int32,11),
					new MySqlParameter("@datadepid", MySqlDbType.Int32,11),
					new MySqlParameter("@databranchid", MySqlDbType.Int32,11),
					new MySqlParameter("@datadepname", MySqlDbType.VarChar,100),
					new MySqlParameter("@databranchname", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataaddusername", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataaddtime", MySqlDbType.DateTime)};
			parameters[0].Value = model.gid;
			parameters[1].Value = model.type;
			parameters[2].Value = model.sontype;
			parameters[3].Value = model.sontypeid;
			parameters[4].Value = model.sontypeinfo;
			parameters[5].Value = model.orderNo;
			parameters[6].Value = model.storeid;
			parameters[7].Value = model.state;
			parameters[8].Value = model.endtime;
			parameters[9].Value = model.addtime;
			parameters[10].Value = model.adduserid;
			parameters[11].Value = model.addusername;
			parameters[12].Value = model.allprice;
			parameters[13].Value = model.inoutusertype;
			parameters[14].Value = model.inoutuserid;
			parameters[15].Value = model.inoutusername;
			parameters[16].Value = model.inoutuseraddress;
			parameters[17].Value = model.inoutusertel;
			parameters[18].Value = model.inoutuserteluser;
			parameters[19].Value = model.dataadduserid;
			parameters[20].Value = model.datadepid;
			parameters[21].Value = model.databranchid;
			parameters[22].Value = model.datadepname;
			parameters[23].Value = model.databranchname;
			parameters[24].Value = model.dataaddusername;
			parameters[25].Value = model.dataaddtime;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(hcrainMvc.Model.herp_inoutorder model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update herp_inoutorder set ");
			strSql.Append("gid=@gid,");
			strSql.Append("type=@type,");
			strSql.Append("sontype=@sontype,");
			strSql.Append("sontypeid=@sontypeid,");
			strSql.Append("sontypeinfo=@sontypeinfo,");
			strSql.Append("orderNo=@orderNo,");
			strSql.Append("storeid=@storeid,");
			strSql.Append("state=@state,");
			strSql.Append("endtime=@endtime,");
			strSql.Append("addtime=@addtime,");
			strSql.Append("adduserid=@adduserid,");
			strSql.Append("addusername=@addusername,");
			strSql.Append("allprice=@allprice,");
			strSql.Append("inoutusertype=@inoutusertype,");
			strSql.Append("inoutuserid=@inoutuserid,");
			strSql.Append("inoutusername=@inoutusername,");
			strSql.Append("inoutuseraddress=@inoutuseraddress,");
			strSql.Append("inoutusertel=@inoutusertel,");
			strSql.Append("inoutuserteluser=@inoutuserteluser,");
			strSql.Append("dataadduserid=@dataadduserid,");
			strSql.Append("datadepid=@datadepid,");
			strSql.Append("databranchid=@databranchid,");
			strSql.Append("datadepname=@datadepname,");
			strSql.Append("databranchname=@databranchname,");
			strSql.Append("dataaddusername=@dataaddusername,");
			strSql.Append("dataaddtime=@dataaddtime");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@gid", MySqlDbType.VarChar,36),
					new MySqlParameter("@type", MySqlDbType.VarChar,50),
					new MySqlParameter("@sontype", MySqlDbType.VarChar,50),
					new MySqlParameter("@sontypeid", MySqlDbType.Int64,20),
					new MySqlParameter("@sontypeinfo", MySqlDbType.VarChar,200),
					new MySqlParameter("@orderNo", MySqlDbType.VarChar,100),
					new MySqlParameter("@storeid", MySqlDbType.Int64,20),
					new MySqlParameter("@state", MySqlDbType.VarChar,100),
					new MySqlParameter("@endtime", MySqlDbType.DateTime),
					new MySqlParameter("@addtime", MySqlDbType.DateTime),
					new MySqlParameter("@adduserid", MySqlDbType.Int64,20),
					new MySqlParameter("@addusername", MySqlDbType.VarChar,100),
					new MySqlParameter("@allprice", MySqlDbType.Decimal,10),
					new MySqlParameter("@inoutusertype", MySqlDbType.VarChar,10),
					new MySqlParameter("@inoutuserid", MySqlDbType.Int64,20),
					new MySqlParameter("@inoutusername", MySqlDbType.VarChar,100),
					new MySqlParameter("@inoutuseraddress", MySqlDbType.VarChar,200),
					new MySqlParameter("@inoutusertel", MySqlDbType.VarChar,100),
					new MySqlParameter("@inoutuserteluser", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataadduserid", MySqlDbType.Int32,11),
					new MySqlParameter("@datadepid", MySqlDbType.Int32,11),
					new MySqlParameter("@databranchid", MySqlDbType.Int32,11),
					new MySqlParameter("@datadepname", MySqlDbType.VarChar,100),
					new MySqlParameter("@databranchname", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataaddusername", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataaddtime", MySqlDbType.DateTime),
					new MySqlParameter("@id", MySqlDbType.Int64,20)};
			parameters[0].Value = model.gid;
			parameters[1].Value = model.type;
			parameters[2].Value = model.sontype;
			parameters[3].Value = model.sontypeid;
			parameters[4].Value = model.sontypeinfo;
			parameters[5].Value = model.orderNo;
			parameters[6].Value = model.storeid;
			parameters[7].Value = model.state;
			parameters[8].Value = model.endtime;
			parameters[9].Value = model.addtime;
			parameters[10].Value = model.adduserid;
			parameters[11].Value = model.addusername;
			parameters[12].Value = model.allprice;
			parameters[13].Value = model.inoutusertype;
			parameters[14].Value = model.inoutuserid;
			parameters[15].Value = model.inoutusername;
			parameters[16].Value = model.inoutuseraddress;
			parameters[17].Value = model.inoutusertel;
			parameters[18].Value = model.inoutuserteluser;
			parameters[19].Value = model.dataadduserid;
			parameters[20].Value = model.datadepid;
			parameters[21].Value = model.databranchid;
			parameters[22].Value = model.datadepname;
			parameters[23].Value = model.databranchname;
			parameters[24].Value = model.dataaddusername;
			parameters[25].Value = model.dataaddtime;
			parameters[26].Value = model.id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(long id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from herp_inoutorder ");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int64)
			};
			parameters[0].Value = id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from herp_inoutorder ");
			strSql.Append(" where id in ("+idlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public hcrainMvc.Model.herp_inoutorder GetModel(long id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,gid,type,sontype,sontypeid,sontypeinfo,orderNo,storeid,state,endtime,addtime,adduserid,addusername,allprice,inoutusertype,inoutuserid,inoutusername,inoutuseraddress,inoutusertel,inoutuserteluser,dataadduserid,datadepid,databranchid,datadepname,databranchname,dataaddusername,dataaddtime from herp_inoutorder ");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int64)
			};
			parameters[0].Value = id;

			hcrainMvc.Model.herp_inoutorder model=new hcrainMvc.Model.herp_inoutorder();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public hcrainMvc.Model.herp_inoutorder DataRowToModel(DataRow row)
		{
			hcrainMvc.Model.herp_inoutorder model=new hcrainMvc.Model.herp_inoutorder();
			if (row != null)
			{
				if(row["id"]!=null && row["id"].ToString()!="")
				{
					model.id=long.Parse(row["id"].ToString());
				}
				if(row["gid"]!=null)
				{
					model.gid=row["gid"].ToString();
				}
				if(row["type"]!=null)
				{
					model.type=row["type"].ToString();
				}
				if(row["sontype"]!=null)
				{
					model.sontype=row["sontype"].ToString();
				}
				if(row["sontypeid"]!=null && row["sontypeid"].ToString()!="")
				{
					model.sontypeid=long.Parse(row["sontypeid"].ToString());
				}
				if(row["sontypeinfo"]!=null)
				{
					model.sontypeinfo=row["sontypeinfo"].ToString();
				}
				if(row["orderNo"]!=null)
				{
					model.orderNo=row["orderNo"].ToString();
				}
				if(row["storeid"]!=null && row["storeid"].ToString()!="")
				{
					model.storeid=long.Parse(row["storeid"].ToString());
				}
				if(row["state"]!=null)
				{
					model.state=row["state"].ToString();
				}
				if(row["endtime"]!=null && row["endtime"].ToString()!="")
				{
					model.endtime=DateTime.Parse(row["endtime"].ToString());
				}
				if(row["addtime"]!=null && row["addtime"].ToString()!="")
				{
					model.addtime=DateTime.Parse(row["addtime"].ToString());
				}
				if(row["adduserid"]!=null && row["adduserid"].ToString()!="")
				{
					model.adduserid=long.Parse(row["adduserid"].ToString());
				}
				if(row["addusername"]!=null)
				{
					model.addusername=row["addusername"].ToString();
				}
				if(row["allprice"]!=null && row["allprice"].ToString()!="")
				{
					model.allprice=decimal.Parse(row["allprice"].ToString());
				}
				if(row["inoutusertype"]!=null)
				{
					model.inoutusertype=row["inoutusertype"].ToString();
				}
				if(row["inoutuserid"]!=null && row["inoutuserid"].ToString()!="")
				{
					model.inoutuserid=long.Parse(row["inoutuserid"].ToString());
				}
				if(row["inoutusername"]!=null)
				{
					model.inoutusername=row["inoutusername"].ToString();
				}
				if(row["inoutuseraddress"]!=null)
				{
					model.inoutuseraddress=row["inoutuseraddress"].ToString();
				}
				if(row["inoutusertel"]!=null)
				{
					model.inoutusertel=row["inoutusertel"].ToString();
				}
				if(row["inoutuserteluser"]!=null)
				{
					model.inoutuserteluser=row["inoutuserteluser"].ToString();
				}
				if(row["dataadduserid"]!=null && row["dataadduserid"].ToString()!="")
				{
					model.dataadduserid=int.Parse(row["dataadduserid"].ToString());
				}
				if(row["datadepid"]!=null && row["datadepid"].ToString()!="")
				{
					model.datadepid=int.Parse(row["datadepid"].ToString());
				}
				if(row["databranchid"]!=null && row["databranchid"].ToString()!="")
				{
					model.databranchid=int.Parse(row["databranchid"].ToString());
				}
				if(row["datadepname"]!=null)
				{
					model.datadepname=row["datadepname"].ToString();
				}
				if(row["databranchname"]!=null)
				{
					model.databranchname=row["databranchname"].ToString();
				}
				if(row["dataaddusername"]!=null)
				{
					model.dataaddusername=row["dataaddusername"].ToString();
				}
				if(row["dataaddtime"]!=null && row["dataaddtime"].ToString()!="")
				{
					model.dataaddtime=DateTime.Parse(row["dataaddtime"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,gid,type,sontype,sontypeid,sontypeinfo,orderNo,storeid,state,endtime,addtime,adduserid,addusername,allprice,inoutusertype,inoutuserid,inoutusername,inoutuseraddress,inoutusertel,inoutuserteluser,dataadduserid,datadepid,databranchid,datadepname,databranchname,dataaddusername,dataaddtime ");
			strSql.Append(" FROM herp_inoutorder ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM herp_inoutorder ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from herp_inoutorder T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "herp_inoutorder";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

